package neo.app.action;

import java.util.List;
import java.util.Map;

import neo.core.common.PagingList;
import neo.core.util.MapUtil;

public class TaskAction extends BaseAction {
	private PagingList taskList;
	private List clientList;
	private List deliverTypeList;
	private List payTypeList;
	private List lineList;
	private Map task;
	
	//任务单列表
	public String list() throws Exception{
		taskList = getServMgr().getTaskService().getAllTask();
		return "list";
	}
	
	//添加任务单准备
	public String addPre() throws Exception {
		clientList = getServMgr().getTaskService().getAllClient();
		deliverTypeList = getServMgr().getTaskService().getAllDeliverType();
		payTypeList = getServMgr().getTaskService().getAllPayType();
		lineList = getServMgr().getTaskService().getAllLine();
		
		return "addPre";
	}
	
	//添加任务单
	public String add() throws Exception {
		if(getServMgr().getTaskService().addTask(getParameters())){
			addMessage("添加成功");
			addRedirURL("返回", "task!addPre.action");
		}else{
			addMessage("操作失败");
			addRedirURL("返回", "@back");
		}
		return EXECUTE_RESULT;
	}
	
	
	//查看任务单
	public String view() throws Exception {
		task = getServMgr().getTaskService().findTaskById(MapUtil.getIntFromMap(getParameters(), "task_id"));
		return "view";
	}
	
	//修改任务单 准备
	public String editPre() throws Exception {
		//1、判断，只有处于【未执行】状态的任务单才能被修改
		int task_flag = MapUtil.getIntFromMap(getParameters(), "task_flag");
		if(task_flag != 0){
			addMessage("只有状态处于【未执行】的任务单才能被修改");
			addRedirURL("返回", "task!list.action");
			return EXECUTE_RESULT;
		}
		task = getServMgr().getTaskService().findTaskById(MapUtil.getIntFromMap(getParameters(), "task_id"));
		deliverTypeList = getServMgr().getTaskService().getAllDeliverType();
		payTypeList = getServMgr().getTaskService().getAllPayType();
		lineList = getServMgr().getTaskService().getAllLine();
		
		return "editPre";
	}
	
	//修改任务单
	public String edit() throws Exception {
		if(getServMgr().getTaskService().editTask(getParameters())){
			addMessage("修改成功");
			addRedirURL("返回", "task!list.action");
		}else{
			addMessage("操作失败");
			addRedirURL("返回", "@back");
		}
		return EXECUTE_RESULT;
	}
	
	//审核任务单 准备
	public String checkPre() throws Exception {
		taskList = getServMgr().getTaskService().getUnDoTasks();
		return "checkPre";
	}
	
	//审核任务单
	public String check() throws Exception {
		getServMgr().getTaskService().checkTask(getParameters());
		return "check";
	}
	
	//整合任务单
	public String integratePre() throws Exception {
		taskList = getServMgr().getTaskService().getUnDoTasksOrderByPath();
		return "integratePre";
	}
	
	//拆分任务单
	public String split() throws Exception {
		
		return "split";
	}
	
	//结单 准备
	public String endTaskPre() throws Exception {
		taskList = getServMgr().getTaskService().getDoingTasks();
		return "endTaskPre";
	}
	
	//结单
	public String end(){
		getServMgr().getTaskService().endTask(getParameters());
		return "end";
	}
	
	//付款 准备
	public String payPre() throws Exception {
		//1、判断，只有处于【执行中】状态的任务单才能被修改
		int task_flag = MapUtil.getIntFromMap(getParameters(), "task_flag");
		if(task_flag != 1){
			addMessage("只有状态处于【执行中】的任务单才能付款");
			addRedirURL("返回", "@back");
			return EXECUTE_RESULT;
		}
		
		task = getServMgr().getTaskService().findTaskById(MapUtil.getIntFromMap(getParameters(), "task_id"));
		
		return "payPre";
	}
	
	//付款
	public String pay() throws Exception {
		getServMgr().getTaskService().pay(getParameters());
		return "pay";
	}
	
	
	//------------
	public PagingList getTaskList() {
		return taskList;
	}

	public void setTaskList(PagingList taskList) {
		this.taskList = taskList;
	}

	public List getClientList() {
		return clientList;
	}

	public void setClientList(List clientList) {
		this.clientList = clientList;
	}

	public List getDeliverTypeList() {
		return deliverTypeList;
	}

	public void setDeliverTypeList(List deliverTypeList) {
		this.deliverTypeList = deliverTypeList;
	}

	public List getPayTypeList() {
		return payTypeList;
	}

	public void setPayTypeList(List payTypeList) {
		this.payTypeList = payTypeList;
	}

	public List getLineList() {
		return lineList;
	}

	public void setLineList(List lineList) {
		this.lineList = lineList;
	}

	public Map getTask() {
		return task;
	}

	public void setTask(Map task) {
		this.task = task;
	}
}
